package com.example.demo111111.common;

import cn.hutool.core.date.DateUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.example.demo111111.service.UserService;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;


import java.util.Date;

@Component
public class JwtTokenUtils {

    private static UserService staticUserService;

    @Resource
    private UserService userService;

    @PostConstruct
    public void setUserService() {
        userService = staticUserService;
    }


    public static String genToken(String account, String password) {
        return JWT.create().withAudience(account)//将account保存在载荷中
                .withExpiresAt(DateUtil.offsetHour(new Date(), 2))//设置token有效时间
                .sign(Algorithm.HMAC256(password));//以password为密钥进行加密
    }

}


